<?php 
include_once 'functions.php';

////////////////////////////////////////////////////////////////////////////////////////
//																				FEEDBACK 
////////////////////////////////////////////////////////////////////////////////////////
	$resultsFeedback= "You have not attempted this test";
if ($_SESSION['score'] <= 5) {
     $resultsFeedback = "You have less than 5, you should...";
}
if ($_SESSION['score'] > 6 && $_SESSION['score'] < 9){
    $resultsFeedback = "You have between 5 and 8, you should...";
}
if ($_SESSION['score'] >8){
       $resultsFeedback = "You have more than 9, you should...";
}
if (!$_SESSION['score']){
       $resultsFeedback = "You have not attempted this test...";
}
////////////////////////////////////////////////////////////////////////////////////////
//																		   TEST FEEDBACK
////////////////////////////////////////////////////////////////////////////////////////
$con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);   
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else {
$query = "SELECT * FROM studentresponse WHERE testID = "
. "'" . $testID . "'"
.  " AND studentID =" 
. "'".  $_SESSION['studentID'] . "'"
.  " AND attempt = 2";
$result = mysqli_query($con, $query);

if ($result) {

                while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

                    $comments[] = $row;
                }
                $ret = $comments;
            } else {
                //no result
               
            }
if (isset($comments))
  {
	  for ($i=0; $i<count($comments); $i++)
	  {
	echo "<div><p>";
	echo date('d-m-Y H:i  ', strtotime($comments[$i]["comment_submitted"]));
	echo $comments[$i]["comment_name"];
	echo  " said:";
	echo  "</p>";
	echo "<p class='commentBody'>";
	echo $comments[$i]["comment_text"];
	echo "</p>";
	echo "</div>";	  }  }
  
  	else  {
	echo "<p>No comments - be the first to post one!</p>";	  }
?>

  ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="styles/styles.css" type="text/css" />
<title>mcq</title>
</head>
<body>
<div id="header"> </div>
<div id="container">
  <div id="mainContent">
  <h1>Feedback</h1>
    <h2>You scored
      <?php echo $_SESSION['score']?>
      /10</h2>
    <p>
      <?php echo $resultsFeedback ?>
    </p>
 
 


	 

 <?php
// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,$query);
	$selectedAnswer = $rowContent[0][3];
		$correctAnswer = $rowContent[0][4];
for ($row = 0; $row < 10; $row++)
  {
  echo "<h2>Question ";
  echo $row+1;
  echo "</h2>";
  for ($col = 3; $col < 4; $col++)
    {
		$selectedAnswer = $rowContent[$row][$col];
    echo "<p>You said: ".$rowContent[$row][$col]."</p>";
    }
	for ($col = 4; $col < 5; $col++)
    {
    $correctAnswer = $rowContent[$row][$col];
    }
 if ($selectedAnswer == $correctAnswer) {
		
		$feedbackStatus = "<span class='green'>You were correct.</span>";
        } 
				else {
        $feedbackStatus = "<span class='red'>You were incorrect,</span> the correct answer was $correctAnswer.";
		} 
		echo $feedbackStatus;
  }
}
?> 

     
    <p class='smiling'>Incorrect Answers:
      <?php echo print_r(array_values($_SESSION['incorrect']))?>
    </p>
    <p class='smiling'>Correct Answers:
      <?php echo print_r(array_values($_SESSION['correct']))?>
    </p>
    <p class='smiling'>Selected Answers:
      <?php echo $selectedAnswer ?>
    </p>
    <p class='smiling'>Score:
      <?php echo $score ?>
    </p>
    <p class='smiling'>Num:
      <?php echo $num ?>
    </p>
    <p class='smiling'>Last:
      <?php echo $last ?>
      |
      <?php echo ($_SESSION['finished'])?>
    </p>
    <p class='smiling'>Session score:
      <?php echo ($_SESSION['score'])?>
    </p>
    <p class='smiling'>Student ID:
      <?php echo ($_SESSION['studentID'])?>
    </p>
  </div>
</div>
</body>
</html>